home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / internet / sweeper / samples / docobj / iipsite.cpp < prev    next >
C/C++ Source or Header  |  1995-11-22  |  10KB  |  412 lines

  1. /*
  2.  * IIPSITE.CPP
  3.  * IOleInPlaceSite for Document Objects CSite class
  4.  *
  5.  * Copyright (c)1995 Microsoft Corporation, All Rights Reserved
  6.  * Kraig Brockschmidt, kraigb@microsoft.com
  7.  */
  8.  
  9.  
  10. #include "framer.h"
  11.  
  12.  
  13. /*
  14.  * CImpIOleInPlaceSite::CImpIOleInPlaceSite
  15.  * CImpIOleInPlaceSite::~CImpIOleInPlaceSite
  16.  *
  17.  * Parameters (Constructor):
  18.  *  pSite           PCSite of the site we're in.
  19.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  20.  */
  21.  
  22. CImpIOleInPlaceSite::CImpIOleInPlaceSite(PCSite pSite
  23.     , LPUNKNOWN pUnkOuter)
  24.     {
  25.     m_cRef=0;
  26.     m_pSite=pSite;
  27.     m_pUnkOuter=pUnkOuter;
  28.     return;
  29.     }
  30.  
  31. CImpIOleInPlaceSite::~CImpIOleInPlaceSite(void)
  32.     {
  33.     return;
  34.     }
  35.  
  36.  
  37.  
  38. /*
  39.  * CImpIOleInPlaceSite::QueryInterface
  40.  * CImpIOleInPlaceSite::AddRef
  41.  * CImpIOleInPlaceSite::Release
  42.  *
  43.  * Purpose:
  44.  *  IUnknown members for CImpIOleInPlaceSite object.
  45.  */
  46.  
  47. STDMETHODIMP CImpIOleInPlaceSite::QueryInterface(REFIID riid
  48.     , void **ppv)
  49.     {
  50.     return m_pUnkOuter->QueryInterface(riid, ppv);
  51.     }
  52.  
  53.  
  54. STDMETHODIMP_(ULONG) CImpIOleInPlaceSite::AddRef(void)
  55.     {
  56.     ++m_cRef;
  57.     return m_pUnkOuter->AddRef();
  58.     }
  59.  
  60. STDMETHODIMP_(ULONG) CImpIOleInPlaceSite::Release(void)
  61.     {
  62.     --m_cRef;
  63.     return m_pUnkOuter->Release();
  64.     }
  65.  
  66.  
  67.  
  68.  
  69. /*
  70.  * CImpIOleInPlaceActiveObject::GetWindow
  71.  *
  72.  * Purpose:
  73.  *  Retrieves the handle of the window associated with the object
  74.  *  on which this interface is implemented.
  75.  *
  76.  * Parameters:
  77.  *  phWnd           HWND * in which to store the window handle.
  78.  *
  79.  * Return Value:
  80.  *  HRESULT         NOERROR if successful, E_FAIL if there is no
  81.  *                  window.
  82.  */
  83.  
  84. STDMETHODIMP CImpIOleInPlaceSite::GetWindow(HWND *phWnd)
  85.     {
  86.     //This is the client-area window in the frame
  87.     *phWnd=m_pSite->m_hWnd;
  88.     return NOERROR;
  89.     }
  90.  
  91.  
  92.  
  93.  
  94. /*
  95.  * CImpIOleInPlaceActiveObject::ContextSensitiveHelp
  96.  *
  97.  * Purpose:
  98.  *  Instructs the object on which this interface is implemented to
  99.  *  enter or leave a context-sensitive help mode.
  100.  *
  101.  * Parameters:
  102.  *  fEnterMode      BOOL TRUE to enter the mode, FALSE otherwise.
  103.  *
  104.  * Return Value:
  105.  *  HRESULT         NOERROR
  106.  */
  107.  
  108. STDMETHODIMP CImpIOleInPlaceSite::ContextSensitiveHelp
  109.     (BOOL fEnterMode)
  110.     {
  111.     return NOERROR;
  112.     }
  113.  
  114.  
  115.  
  116.  
  117. /*
  118.  * CImpIOleInPlaceSite::CanInPlaceActivate
  119.  *
  120.  * Purpose:
  121.  *  Answers the server whether or not we can currently in-place
  122.  *  activate its object.  By implementing this interface we say
  123.  *  that we support in-place activation, but through this function
  124.  *  we indicate whether the object can currently be activated
  125.  *  in-place.  Iconic aspects, for example, cannot, meaning we
  126.  *  return S_FALSE.
  127.  *
  128.  * Parameters:
  129.  *  None
  130.  *
  131.  * Return Value:
  132.  *  HRESULT         NOERROR if we can in-place activate the object
  133.  *                  in this site, S_FALSE if not.
  134.  */
  135.  
  136. STDMETHODIMP CImpIOleInPlaceSite::CanInPlaceActivate(void)
  137.     {    
  138.     /*
  139.      * We can always in-place activate--no restrictions for DocObjects.
  140.      * We don't worry about other cases since CSite only ever creates
  141.      * embedded files.
  142.      */
  143.     return NOERROR;
  144.     }
  145.  
  146.  
  147.  
  148.  
  149. /*
  150.  * CImpIOleInPlaceSite::OnInPlaceActivate
  151.  *
  152.  * Purpose:
  153.  *  Informs the container that an object is being activated in-place
  154.  *  such that the container can prepare appropriately.  The
  155.  *  container does not, however, make any user interface changes at
  156.  *  this point.  See OnUIActivate.
  157.  *
  158.  * Parameters:
  159.  *  None
  160.  *
  161.  * Return Value:
  162.  *  HRESULT         NOERROR or an appropriate error code.
  163.  */
  164.  
  165. STDMETHODIMP CImpIOleInPlaceSite::OnInPlaceActivate(void)
  166.     {    
  167.     m_pSite->m_pObj->QueryInterface(IID_IOleInPlaceObject
  168.         , (void **)&m_pSite->m_pIOleIPObject);
  169.  
  170.     return NOERROR;
  171.     }
  172.  
  173.  
  174.  
  175.  
  176. /*
  177.  * CImpIOleInPlaceSite::OnInPlaceDeactivate
  178.  *
  179.  * Purpose:
  180.  *  Notifies the container that the object has deactivated itself
  181.  *  from an in-place state.  Opposite of OnInPlaceActivate.  The
  182.  *  container does not change any UI at this point.
  183.  *
  184.  * Parameters:
  185.  *  None
  186.  *
  187.  * Return Value:
  188.  *  HRESULT         NOERROR or an appropriate error code.
  189.  */
  190.  
  191. STDMETHODIMP CImpIOleInPlaceSite::OnInPlaceDeactivate(void)
  192.     {
  193.     /*
  194.      * Since we don't have an Undo command, we can tell the object
  195.      * right away to discard its Undo state.
  196.      */
  197.     m_pSite->Activate(OLEIVERB_DISCARDUNDOSTATE);
  198.     ReleaseInterface(m_pSite->m_pIOleIPObject);
  199.     return NOERROR;
  200.     }
  201.  
  202.  
  203.  
  204.  
  205. /*
  206.  * CImpIOleInPlaceSite::OnUIActivate
  207.  *
  208.  * Purpose:
  209.  *  Informs the container that the object is going to start munging
  210.  *  around with user interface, like replacing the menu.  The
  211.  *  container should remove any relevant UI in preparation.
  212.  *
  213.  * Parameters:
  214.  *  None
  215.  *
  216.  * Return Value:
  217.  *  HRESULT         NOERROR or an appropriate error code.
  218.  */
  219.  
  220. STDMETHODIMP CImpIOleInPlaceSite::OnUIActivate(void)
  221.     {
  222.     //No state we have to set up here.
  223.     return NOERROR;
  224.     }
  225.  
  226.  
  227.  
  228.  
  229. /*
  230.  * CImpIOleInPlaceSite::OnUIDeactivate
  231.  *
  232.  * Purpose:
  233.  *  Informs the container that the object is deactivating its
  234.  *  in-place user interface at which time the container may
  235.  *  reinstate its own.  Opposite of OnUIActivate.
  236.  *
  237.  * Parameters:
  238.  *  fUndoable       BOOL indicating if the object will actually
  239.  *                  perform an Undo if the container calls
  240.  *                  ReactivateAndUndo.
  241.  *
  242.  * Return Value:
  243.  *  HRESULT         NOERROR or an appropriate error code.
  244.  */
  245.  
  246. STDMETHODIMP CImpIOleInPlaceSite::OnUIDeactivate(BOOL fUndoable)
  247.     {
  248.     //Set focus back to the frame
  249.     SetFocus(m_pSite->m_pFR->Window());
  250.  
  251.     //Show our menu again
  252.     m_pSite->m_pFR->SetMenu(NULL, NULL, NULL);
  253.  
  254.     return NOERROR;
  255.     }
  256.  
  257.  
  258.  
  259.  
  260. /*
  261.  * CImpIOleInPlaceSite::DeactivateAndUndo
  262.  *
  263.  * Purpose:
  264.  *  If immediately after activation the object does an Undo, the
  265.  *  action being undone is the activation itself, and this call
  266.  *  informs the container that this is, in fact, what happened.
  267.  *  The container should call IOleInPlaceObject::UIDeactivate.
  268.  *
  269.  * Parameters:
  270.  *  None
  271.  *
  272.  * Return Value:
  273.  *  HRESULT         NOERROR or an appropriate error code.
  274.  */
  275.  
  276. STDMETHODIMP CImpIOleInPlaceSite::DeactivateAndUndo(void)
  277.     {
  278.     m_pSite->m_pIOleIPObject->InPlaceDeactivate();
  279.     return NOERROR;
  280.     }
  281.  
  282.  
  283.  
  284.  
  285. /*
  286.  * CImpIOleInPlaceSite::DiscardUndoState
  287.  *
  288.  * Purpose:
  289.  *  Informs the container that something happened in the object
  290.  *  that means the container should discard any undo information
  291.  *  it currently maintains for the object.
  292.  *
  293.  * Parameters:
  294.  *  None
  295.  *
  296.  * Return Value:
  297.  *  HRESULT         NOERROR or an appropriate error code.
  298.  */
  299.  
  300. STDMETHODIMP CImpIOleInPlaceSite::DiscardUndoState(void)
  301.     {
  302.     return E_NOTIMPL;
  303.     }
  304.  
  305.  
  306.  
  307.  
  308. /*
  309.  * CImpIOleInPlaceSite::GetWindowContext
  310.  *
  311.  * Purpose:
  312.  *  Provides an in-place object with pointers to the frame and
  313.  *  document level in-place interfaces (IOleInPlaceFrame and
  314.  *  IOleInPlaceUIWindow) such that the object can do border
  315.  *  negotiation and so forth.  Also requests the position and
  316.  *  clipping rectangles of the object in the container and a
  317.  *  pointer to an OLEINPLACEFRAME info structure which contains
  318.  *  accelerator information.
  319.  *
  320.  *  Note that the two interfaces this call returns are not
  321.  *  available through QueryInterface on IOleInPlaceSite since they
  322.  *  live with the frame and document, but not the site.
  323.  *
  324.  * Parameters:
  325.  *  ppIIPFrame      LPOLEINPLACEFRAME * in which to return the
  326.  *                  AddRef'd pointer to the container's
  327.  *                  IOleInPlaceFrame.
  328.  *  ppIIPUIWindow   LPOLEINPLACEUIWINDOW * in which to return
  329.  *                  the AddRef'd pointer to the container document's
  330.  *                  IOleInPlaceUIWindow.
  331.  *  prcPos          LPRECT in which to store the object's position.
  332.  *  prcClip         LPRECT in which to store the object's visible
  333.  *                  region.
  334.  *  pFI             LPOLEINPLACEFRAMEINFO to fill with accelerator
  335.  *                  stuff.
  336.  *
  337.  * Return Value:
  338.  *  HRESULT         NOERROR
  339.  */
  340.  
  341. STDMETHODIMP CImpIOleInPlaceSite::GetWindowContext
  342.     (LPOLEINPLACEFRAME *ppIIPFrame, LPOLEINPLACEUIWINDOW
  343.     *ppIIPUIWindow, LPRECT prcPos, LPRECT prcClip
  344.     , LPOLEINPLACEFRAMEINFO pFI)
  345.     {
  346.     *ppIIPUIWindow=NULL;
  347.     m_pSite->m_pFR->QueryInterface(IID_IOleInPlaceFrame
  348.         , (void **)ppIIPFrame);
  349.     
  350.     if (NULL!=prcPos)
  351.         GetClientRect(m_pSite->m_hWnd, prcPos);
  352.  
  353.     *prcClip=*prcPos;
  354.  
  355.     pFI->cb=sizeof(OLEINPLACEFRAMEINFO);
  356.     pFI->fMDIApp=FALSE;
  357.     pFI->hwndFrame=m_pSite->m_pFR->Window();
  358.     pFI->haccel=m_pSite->m_pFR->Accelerators();
  359.     pFI->cAccelEntries=CACCELERATORS;
  360.  
  361.     return NOERROR;
  362.     }
  363.  
  364.  
  365.  
  366.  
  367. /*
  368.  * CImpIOleInPlaceSite::Scroll
  369.  *
  370.  * Purpose:
  371.  *  Asks the container to scroll the document, and thus the object,
  372.  *  by the given amounts in the sz parameter.
  373.  *
  374.  * Parameters:
  375.  *  sz              SIZE containing signed horizontal and vertical
  376.  *                  extents by which the container should scroll.
  377.  *                  These are in device units.
  378.  *
  379.  * Return Value:
  380.  *  HRESULT         NOERROR
  381.  */
  382.  
  383. STDMETHODIMP CImpIOleInPlaceSite::Scroll(SIZE sz)
  384.     {
  385.     //Not needed for DocObjects
  386.     return E_NOTIMPL;
  387.     }
  388.  
  389.  
  390.  
  391.  
  392. /*
  393.  * CImpIOleInPlaceSite::OnPosRectChange
  394.  *
  395.  * Purpose:
  396.  *  Informs the container that the in-place object was resized.
  397.  *  The container must call IOleInPlaceObject::SetObjectRects.
  398.  *  This does not change the site's rectangle in any case.
  399.  *
  400.  * Parameters:
  401.  *  prcPos          LPCRECT containing the new size of the object.
  402.  *
  403.  * Return Value:
  404.  *  HRESULT         NOERROR
  405.  */
  406.  
  407. STDMETHODIMP CImpIOleInPlaceSite::OnPosRectChange(LPCRECT prcPos)
  408.     {
  409.     //Not needed for DocObjects
  410.     return E_NOTIMPL;
  411.     }
  412.